<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>13-箭头函数</title>
</head>
<body>
    <script>
        // 箭头函数
        let play = function () {
            console.log('今晚吃鸡');
        }
        play();
        let game = () => {
            console.log('王者荣耀');
        }
        game();


        // 1. 如果形参只有一个，小括弧可以省略
        // let add = (num) => {}
        let add = num => {
            num++;
            console.log(num);  // 13
        };
        add(12);

        // 2. 如果逻辑体只有一行代码，return和{} 都可以省略
        // let ball = score => score + 5;
        // console.log(ball(10));  //15

        // let ball2 = (score) => {
        //    return 1111;
        // } 
        // console.log(ball2());

        // 3. this 上下文的this,定义箭头函数位置的this
        const cook = function () {
            console.log(this);      // window
            return () => {
                console.log(this);  // window
            }
        };
        let temp = cook();
        temp();

     console.log('--------------案例2----------');
      function Star(sex, age) {
      this.sex = sex;
      this.age = age;
      console.log(this);   // Star
      this.run = () => {
        console.log(this);   // Star
        console.log('就这么跑来跑去');
      }
    }
    let lee = new Star('男', 22);
    lee.run();

    </script>
</body>
</html>